<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/9/21
 * Time: 21:36
 */

namespace Admin\Controller;


class MessageController extends CommonController
{
    public function index()
    {
        $map = array();
        if (I('get.keyword') != '') {
            $map['name'] = array('like', '%' . I('get.keyword') . '%');
        }
        $list = D('message')->getlist($map);

        if ($list['list']){
            foreach ($list['list'] as $key=>$val){
                $list['list'][$key]['user_id'] = empty($val['user_id']) ? "游客" : M('wx_users')->where(array('id'=>$val['user_id']))->getFeild('nickname');
            }
        }
        $this->assign('count', $list['count']);
        $this->assign('totalPages', $list['totalPages']);// 总分页数
        $this->assign('nowPage', $list['nowPage']);// 当前页
        $this->assign('list', $list['list']);
        $this->assign('page', $list['show']);
        $this->display();
    }
    public function del(){
        $ids = I('ids');
        $msg ['errno'] = 0;
        $msg ['error'] = "删除成功";
        if (is_array($ids)) {
            foreach ($ids as $id) {
                $data['id'] = $id;
                $flag = D('message')->del($data);
            }
        }
        if (!$flag) {
            $msg ['errno'] = 1;
            $msg ['error'] = "删除失败！";
        }

        $this->ajaxReturn($msg);
    }
}